package com.gilgamesh.mall.product.sql;

import com.gilgamesh.mall.sdk.bean.product.StockEntity;
import com.gilgamesh.mall.sdk.util.BeanUtil;
import com.gilgamesh.mall.sdk.util.StringUtil;

/**
 * Created by Peiyao.Wang on 2021/1/13
 *
 * @author Peiyao.Wang
 * @date 2021/1/13
 */

public class StockSql {
    public  String listStocks(StockEntity stockEntity){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from t_stock");
        if(BeanUtil.isLogicalNull(stockEntity)){
            return sb.toString();
        }
        int times = 0;
        if (stockEntity.getId() != null){
            if(times == 0){
                sb.append("where");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("id = #{id}");
        }
        if(StringUtil.isNotEmpty(stockEntity.getSkuCode())){
            if(times == 0){
                sb.append("where");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("sku_code = #{skuCode}");
        }
        if (stockEntity.getRemainingQuantity() != null){
            if(times == 0){
                sb.append("where");
            }else if(times > 0){
                sb.append("and");
            }
            times++;
            sb.append("remaining_quantity = #{remainingQuantity}");
        }

        return sb.toString();
    }
}
